//
//  ViewController.m
//  MapDemo
//
//  Created by HOCVIEN on 4/18/15.
//  Copyright (c) 2015 GV. All rights reserved.
//

#import "ViewController.h"
#import <MapKit/MapKit.h>
@interface ViewController ()<MKMapViewDelegate>
@property (strong, nonatomic) IBOutlet MKMapView *myMapView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    // cai MKPointAnnotation
    int a = 0;
    a--;
    NSLog(@"a = %d",a);

    int b = 0;
    b--;
    NSLog(@"b = %d", b);


    b++;

    self.myMapView.delegate = self;
    for (int i = 0; i < 100; i++) {
        MKPointAnnotation* annotation = [[MKPointAnnotation alloc] init];
        annotation.title = @"safkj";
        annotation.subtitle = @"123424";
        annotation.coordinate = CLLocationCoordinate2DMake(rand() % 80, rand() % 80);
        [self.myMapView addAnnotation:annotation];
        
        
    }
    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(40, 40);
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(coordinate, 1000000, 1000000);
    [self.myMapView setRegion:region];
    
}


- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
    
    NSString* annotationIdentifier = @"my_annotation_view";
    
    MKAnnotationView* annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
    
    if (!annotationView) {
        annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier];
        [annotationView setEnabled:YES];
        [annotationView setCanShowCallout:YES];
    }
    UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
    [button setImage:[UIImage imageNamed:@"icon.png"] forState:UIControlStateNormal];
   // button.imageView.image = [UIImage imageNamed:@"icon.png"];
    [button setUserInteractionEnabled:YES];
    annotationView.leftCalloutAccessoryView = button;
    
    
    UIImageView* imgView2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
    [imgView2 setUserInteractionEnabled:YES];
    imgView2.image = [UIImage imageNamed:@"icon.png"];
    annotationView.rightCalloutAccessoryView = imgView2;
    
    //[annotationView setContentMode:UIViewContentModeScaleToFill];
    
    
    annotationView.image = [UIImage imageNamed:@"icon.png"];
    
    [annotationView setFrame:CGRectMake(0, 0, 40, 40)];
    //[annotationView setBackgroundColor:[UIColor redColor]];
    return annotationView;
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
    NSLog(@"didselected");
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
    NSLog(@"control = %@", control);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
